package com.example.by.mdb.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by BY on 2016/1/7.
 */
public class MyDatabaseHelper extends SQLiteOpenHelper {
    private static int VERSION = 2;

    public MyDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public MyDatabaseHelper(Context context, String name, int version) {
        this(context, name, null, version);
    }

    public MyDatabaseHelper(Context context, String name) {
        this(context, name, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table if not exists employee(employee_id integer primary key autoincrement,"
                + " name varchar(50),"
                + " prop varchar(10),"
                + " worker_no varchar(20),"
                + " grade varchar(10))");
//        db.execSQL(
//                "insert into employee(name,worker_no) values(?,?)",
//                new String[]{"甘晓芳", "71624"});


        db.execSQL("create table if not exists pda_check(check_id integer primary key autoincrement,"
                + " eqpno varchar(50),"
                + " edition varchar(50),"
                + " checkno varchar(50),"
                + " rank varchar(50),"
                + " groupno varchar(50),"
                + " checkitem1 varchar(50),"
                + " checkitem2 varchar(50),"
                + " checkitem3 varchar(50),"
                + " item varchar(50),"
                + " standard1 varchar(50),"
                + " standard2 varchar(50),"
                + " unit varchar(50),"
                + " type varchar(50),"
                + " notice varchar(50),"
                + " frequency varchar(50),"
                + " rst_ng varchar(20),"
                + " file_name varchar(20),"
                + " flag varchar(2) default('0'))");

        db.execSQL("create table if not exists pda_maintain(check_id integer primary key autoincrement,"
                + " eqpno varchar(50),"
                + " edition varchar(50),"
                + " checkno varchar(50),"
                + " rank varchar(50),"
                + " groupno varchar(50),"
                + " checkitem1 varchar(50),"
                + " checkitem2 varchar(50),"
                + " checkitem3 varchar(50),"
                + " item varchar(50),"
                + " standard1 varchar(50),"
                + " standard2 varchar(50),"
                + " unit varchar(50),"
                + " type varchar(50),"
                + " notice varchar(50),"
                + " frequency varchar(50),"
                + " rst_ng varchar(20),"
                + " file_name varchar(20),"
                + " flag varchar(2) default('0'))");
        System.out.println("create");

        db.execSQL("create table if not exists last_edit(edit_id integer primary key autoincrement,"
                + " rst varchar(50),"
                + " lastedit TimeStamp NOT NULL DEFAULT(datetime('now','localtime')),"
                + " eqpno varchar(30),"
                + " checkno varchar(30),"
                + " frequency varchar(20),"
                + " mark varchar(100),"
                + " file_name varchar(20))");

        db.execSQL("create table if not exists result_maintain(maintain_id integer primary key autoincrement,"
                + " check_time TimeStamp NOT NULL DEFAULT(datetime('now','localtime')),"
                + " rst varchar(50),"
                + " empno varchar(30),"
                + " ng varchar(30),"
                + " checkno varchar(30),"
                + " eqpno varchar(30),"
                + " frequency varchar(20),"
                + " rst_ng varchar(30),"
                + " aim varchar(30),"
                + " select_index varchar(30),"
                + " file_name varchar(20))");

        db.execSQL("create table if not exists record(record_id integer primary key autoincrement,"
                + " file_name varchar(10))");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        onCreate(db);
    }
}
